package com.wdc.sort;

import java.util.Arrays;
import java.util.concurrent.ThreadLocalRandom;

public class QuickSortHoare {

    public static void sort(int[] a){

    }

    private static void quick(int[] a,int left,int right){
        if (left >= right){
            return;
        }
        int p = partition(a,left,right);
        quick(a,left,p -1);
        quick(a,p +1,right);
    }

    private static void swap(int[] a ,int i ,int j){
        int t = a[i];
        a[i] = a[j];
        a[j] = t;
    }

    private static int partition(int[] a, int left, int right) {
        int idx = ThreadLocalRandom.current().nextInt(right - left + 1)+ left;  //用随机值来作为基准点 防止最坏情况 造成的 n^2 复杂度
        swap(a,idx,left);
        int i = left;
        int j = right;
        int pv =a[left];
        while (i < j){
            while (i < j && a[j] > pv){
                j--;
            }
            while (i < j && a[i] <= pv){
                i++;
            }
            swap(a,i,j);
        }
        swap(a,left,i);
        return i;
    }

    public static void main(String[] args) {
        int[] arr = {1,5,3,56,3,67};
//        quick(arr,0,arr.length -1);
//        System.out.println(Arrays.toString(arr));

        String s = "123";

        char c = s.charAt(2);
        System.out.println(c);
        Integer i = Integer.valueOf(c - '0');
        System.out.println(i);
        arr[i] = 0;
        System.out.println(Arrays.toString(arr));
    }

}
